<?php
header("Content-Type: text/xml");

echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
echo "<results>";

include_once("root.php");
require_once($ROOT . "model/dao/CodeLookup.php");
require_once($ROOT . "util/CodeLookupUtil.php");

$filter = strtolower( $_GET['filter'] );
$input = strtolower( $_GET['input'] );

$codes = CodeLookupUtil::getCodes("tc_tag", "value");

/*
if (strlen($input) == 0 || stripos(" ", $input) == (strlen($input) - 1))
{
	$input = "";
}
else
{
	$inputs = split(" ", $input);

	$input = $inputs[count($inputs) - 1];
}
*/

foreach ($codes as $code)
{
	$cat = "";
	$value = $code->value;
	if (stripos($value, ":") > 0 && $filter != "")
	{
		$split = split(":", $value);

		$cat = $split[0];
		$value = $split[1];
	}

	if ($filter != $cat)
	{
		continue;
	}

	if (stripos($value, $input) === 0 || $input == "")
	{
	   echo "\n\t<rs>" . $value . "</rs>";
	}
}

echo "</results>";
?>